import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import mplcursors

def f1():
    # Sample time-series data
    data = {
        'Date': pd.date_range(start='2023-01-01', periods=100, freq='D'),
        'Value': np.random.randn(100).cumsum()
    }

    # Convert to DataFrame
    df = pd.DataFrame(data)

    # Plot time-series data
    plt.figure(figsize=(10, 6))
    plt.plot(df['Date'], df['Value'], marker='o', linestyle='-', color='b', label='Value')

    # Customize the graph
    plt.title('Time-Series Data')
    plt.xlabel('Date')
    plt.ylabel('Value')
    plt.legend()
    plt.grid(True)
    plt.xticks(rotation=45)  # Rotate x-axis labels for better readability

    # Show the graph
    plt.tight_layout()
    plt.show()

# Add interactivity with mplcursors
def f2_mlcursors():
    # Sample time-series data
    data = {
        'Date': pd.date_range(start='2023-01-01', periods=100, freq='D'),
        'Value': np.random.randn(100).cumsum()
    }

    # Convert to DataFrame
    df = pd.DataFrame(data)

    # Plot time-series data
    plt.figure(figsize=(10, 6))
    line, = plt.plot(df['Date'], df['Value'], marker='o', linestyle='-', color='b', label='Value')

    # Customize the graph
    plt.title('Time-Series Data')
    plt.xlabel('Date')
    plt.ylabel('Value')
    plt.legend()
    plt.grid(True)
    plt.xticks(rotation=45)  # Rotate x-axis labels for better readability

    # Add interactivity with mplcursors
    cursor = mplcursors.cursor(line, hover=True)
    @cursor.connect("add")
    def on_add(sel):
        sel.annotation.set(text=f'Date: {df["Date"][sel.target.index].date()}\nValue: {df["Value"][sel.target.index]:.2f}',
                        bbox=dict(facecolor='white', alpha=0.8))

    # Show the graph
    plt.tight_layout()
    plt.show()

f1()